Skip to content

Conversation

@sanych-sun
Copy link
Member

@sanych-sun sanych-sun commented Nov 14, 2025

Consolidate Stream extension methods + improve code coverage.
Includes fix for Tailable_cursor_should_be_able_to_be_cancelled_from_a_different_thread_with_expected_result flaky test.

@sanych-sun sanych-sun requested a review from BorisDog November 14, 2025 02:07
@sanych-sun sanych-sun requested a review from a team as a code owner November 14, 2025 02:08
@sanych-sun sanych-sun added the chore Non–user-facing code changes (tests, build scripts, etc.). label Nov 14, 2025
@BorisDog BorisDog requested a review from Copilot November 14, 2025 20:09
Copilot finished reviewing on behalf of BorisDog November 14, 2025 20:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors stream extension methods to consolidate implementations and avoid ThreadPool-dependent I/O methods in the synchronous API. The main changes involve replacing the old API that used OperationContext and TimeSpan parameters with a cleaner API that uses int timeoutMs and CancellationToken parameters directly.

Key Changes:

  • Consolidated stream extension methods with separate timeout handling for sync and async operations
  • Replaced TimeSpan timeout parameters with int timeoutMs (milliseconds) for consistency
  • Improved test coverage by adding dedicated tests for byte array overloads of WriteBytes methods

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/MongoDB.Driver/Core/Misc/StreamExtensionMethods.cs Complete refactoring of ReadBytes/WriteBytes extension methods with new timeout handling mechanism; sync methods now use Timer-based approach while async methods use Task.WhenAny pattern
tests/MongoDB.Driver.Tests/Core/Misc/StreamExtensionMethodsTests.cs Updated all tests to use new API signatures; added comprehensive test coverage for byte array WriteBytes methods; renamed tests for better clarity
src/MongoDB.Driver/GridFS/GridFSBucket.cs Updated ReadBytes/ReadBytesAsync calls to use new API with named cancellationToken parameter
src/MongoDB.Driver/Core/Connections/BinaryConnection.cs Updated ReadBytes/WriteBytes calls with TimeSpan-to-milliseconds conversion at call sites
src/MongoDB.Driver/Core/Connections/Socks5Helper.cs Updated ReadBytes/ReadBytesAsync calls to use new API with named cancellationToken parameter
src/MongoDB.Driver/Core/Compression/SnappyCompressor.cs Simplified ReadBytes calls by removing unnecessary timeout parameters for in-memory operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

(str, state) =>
{
var bytesRead = 0;
while (bytesRead < state.count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Probably not relevant here, but comparing to 0 is a bit faster, so no reason to change previous code that used remainingCount variable. For your consideration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not done everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for spotting this. Now should be done.

Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few minor comments.

(str, state) =>
{
var bytesRead = 0;
while (bytesRead < state.count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not done everywhere.

@sanych-sun sanych-sun requested a review from BorisDog November 24, 2025 23:28
Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sanych-sun sanych-sun merged commit 45d5593 into mongodb:main Nov 25, 2025
303 of 335 checks passed
@sanych-sun sanych-sun deleted the csharp5777 branch November 25, 2025 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Non–user-facing code changes (tests, build scripts, etc.).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants